package com.cskaoyan.controller;


import com.cskaoyan.bean.ad.AdAddBO;
import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Ad;
import com.cskaoyan.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 广告表 前端控制器
 * </p>
 *
 * @author zhiMing
 * @since 2021年11月29日
 */
@RestController
@RequestMapping("/admin/ad")
public class AdController {
    @Autowired
    AdService adService;

    /***
     *
     * @param name 广告标题
     * @param content 广告内容
     * @param baseParam 分页排序信息
     * @return
     */
    @GetMapping("list")
    public BaseRespVo<BaseData> adList(String name, String content, BaseParam baseParam) {
        BaseData baseData = adService.adList(name, content, baseParam);
        return BaseRespVo.ok(baseData);
    }

    @PostMapping("create")
    public BaseRespVo<Ad> adAdd(@RequestBody AdAddBO addBO) {
        Ad adInfo = adService.adAdd(addBO);
        return BaseRespVo.ok(adInfo);
    }

    @PostMapping("update")
    public BaseRespVo<Ad> update(@RequestBody @Valid AdAddBO adBO) {
        Ad ad = adService.adUpdate(adBO);
        return BaseRespVo.ok(ad);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody AdAddBO adBO) {
        int affectRow = adService.adDelete(adBO);
        return BaseRespVo.ok(affectRow);
    }


}

